import { defineStore } from "pinia";
import {
  listGoodsBatch, //查询仓库物资分页列表（带批次）
} from "../../../utils/api/user/userApi";
//列表头
const firstListHeader = [
  "物资名称",
  "物资别名",
  "规格",
  "类型",
  "生产厂家",
  "批次",
  "有效期",
  "产地",
  "品牌",
  "数量",
  "单位",
  "库位",
];
export const useFirstListStore = defineStore(
  "firstList",
  () => {
    const firstTableHeader = firstListHeader; //列表头
    const firstTotalCount = ref(0);
    //列表一数据
    const list: any = [];
    const firstList = reactive({ list });

    //获取列表一
    const getFirstList = async (data: AnyObject) => {
      const res = await listGoodsBatch({
        ...data,
      });
      firstList.list = res.data.list;
      firstTotalCount.value = res.data.totalCount || 0;
    };

    return {
      firstTableHeader, //列表头
      firstList, //列表数据
      getFirstList, //获取列表一数据
      firstTotalCount,
    };
  },
  /**********************************TODO: 持久化***********************/ {
    // 配置持久化
    persist: {
      // 调整为兼容多端的API
      storage: {
        setItem(key, value) {
          uni.setStorageSync(key, value);
        },
        getItem(key) {
          return uni.getStorageSync(key);
        },
      },
      paths: ["firstTableHeader"],
    },
  }
);
